/*
Copyright 2010,2011 Matt Van Der Westhuizen

This file is part of CGLL.

CGLL is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

CGLL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with CGLL.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.chaoticengine.cgll.ui;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

/**
 * Widget to display simple progress / health bars.
 * 
 * @author Matt Van Der Westhuizen <mattpwest@gmail.com>
 */
public abstract class BarWidget extends Widget {
    protected Color c = Color.white;
    protected float percentage = 1.0f;

    public BarWidget(Color col) {
        this.c = col;
    }

    @Override
    public Rectangle getBounds() {
        return(new Rectangle(0, 0, 32, 32));
    }

    @Override
    public void render(Vector2f position, GameContainer gc, StateBasedGame sb, Graphics gr) {
        gr.setColor(c);
        gr.setLineWidth(1.0f);
        gr.drawRect(position.x + 2, position.y + 2, 32 - 4, 32 - 4);
        gr.fillRect(position.x + 4, position.y + 4, (32 - 8) * percentage, 32 - 8);
    }

    public float getPercentage() {
        return percentage;
    }

    public void setPercentage(float value) {
        this.percentage = value;
    }
}
